
package com.funo.government.info.view;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import com.funo.government.info.R;
import com.funo.government.info.bean.AboutInfo;
import com.funo.government.info.utils.BusinessException;
import com.funo.government.info.utils.BusinessResolver.BusinessCallback;
import com.funo.government.info.utils.GovernmentResolver;
import com.funo.government.info.utils.RequestTask;

public class AboutActivity extends BaseActivity {

    private TextView tvContent, tvVersionName;

    private RequestTask mGetAboutTask;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);
        tvContent = (TextView) findViewById(R.id.tvContent);
        tvVersionName = (TextView) findViewById(R.id.tvVersionName);
        PackageManager pm = getPackageManager();
        try {
            PackageInfo pi = pm.getPackageInfo(getPackageName(), PackageManager.GET_CONFIGURATIONS);
            tvVersionName.setText(getString(R.string.version_info, pi.versionName));
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }

        mGetAboutTask = GovernmentResolver.getAbout(new BusinessCallback<AboutInfo>() {

            @Override
            public void onSuccess(AboutInfo t) {
                if (t != null) {
                    tvContent.setText(t.aboutmsg);
                }
            }

            @Override
            public void onError(BusinessException e) {
                e.printStackTrace();
                Toast.makeText(AboutActivity.this, R.string.cannot_connect_server,
                        Toast.LENGTH_SHORT).show();

            }
        });
    }

    @Override
    protected void onDestroy() {
        if (mGetAboutTask != null) {
            mGetAboutTask.cancel(true);
            mGetAboutTask = null;
        }
        super.onDestroy();

    }

}
